<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>an-ui</title>
    <link rel="stylesheet" href="src/demo.css">
    <style>
        nav {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            padding: 10px;

            & a {
                padding: 10px 30px;
                border: 1px solid;
                font-weight: 600;

                &:not(:hover) {
                    text-decoration: none;
                    color: inherit;
                }
            }

        }

        .content {
            border-top: 1px solid;
            padding-block-end: 10px;

            & iframe {
                width: 100%;
                height: calc(100vh - 100px);
                border: none;
            }
        }
    </style>
</head>

<body>
    <nav>
        <a href="src/button/demo.html">button</a>
        <a href="src/form/demo.html">form</a>
        <a href="src/row-col/demo.html">row-col</a>
        <a href="src/popover/demo.html">popover</a>
        <a href="src/modal/demo.html">modal</a>
    </nav>

    <div class="content">
        <iframe src=""></iframe>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            var iframe = document.querySelector('.content iframe')
            var els = document.querySelectorAll('nav a')
            for (let i = 0; i < els.length; i++) {
                const el = els[i];
                el.addEventListener('click', function (e) {
                    e.preventDefault()
                    var href = el.getAttribute('href')
                    jump(href)
                })
            }
            jump()
            function jump(href) {
                if (!href) {
                    href = localStorage.getItem('demo-href')
                }
                if (!href) {
                    href = els[0].getAttribute('href')
                }
                localStorage.setItem('demo-href', href)
                iframe.setAttribute('src', href)
            }
        })

    </script>
</body>

</html>